package com.example.rbac.service.impl;

import com.example.rbac.entity.Page;
import com.example.rbac.entity.Table;
import com.example.rbac.entity.TableField;
import com.example.rbac.mapper.TablesMapper;
import com.example.rbac.service.TablesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TablesServiceImpl extends CurdServiceImpl<TablesMapper, Table> implements TablesService {

    @Override
    public List<String> findTables(String dataName) {
        return repository.findTables(dataName);
    }


    @Override
    public List<TableField> showTable(String tableName)throws Exception {
        return repository.showTable(tableName);
    }

    @Override
    public Page<Table> getPager(Integer pageNum, Integer pageSize) {
        return super.getPager(pageNum, pageSize);
    }

    @Override
    public Page<Table> getPager(Integer pageNum, Integer pageSize, String dataName) {
        if (pageNum == null || pageSize == null) {
            Page page = new Page();
            pageNum = page.getCurrentPageNum();
            pageSize = page.getPerPageSize();
        }
        List<Table> list = repository.getPager((pageNum - 1) * pageSize, pageSize, dataName);
        Page<Table> page = new Page<Table>(pageNum, pageSize, list, repository.getCount(dataName));
        return page;
    }

    @Override
    public Integer getCount(String dataName) {
        return repository.getCount(dataName);
    }
}
